import { App } from "vue";
/**
 * 懒加载图片
 */
export const obs = new IntersectionObserver((enters) => {
  for (let item of enters) {
    if (item.isIntersecting) {
      const img = item.target as HTMLElement;
      img.setAttribute("src", img.dataset.src!);
      obs.unobserve(img);

    }
  }
})
/**
 * 
 *  创建懒加载图片自定义指令
 */
export function createLazy(app: App) {
  app.directive('lazy', {
    mounted(el, _binding, _vnode) {
      obs.observe(el);
    },
  })
}